//
//  LETableViewController.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/9.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "ZDTableViewController.h"
#import <MJRefresh/MJRefresh.h>
#import "ZDNoDataView.h"

@interface ZDTableViewController ()

@property (nonatomic,strong)MJRefreshNormalHeader *header;

// <#售票员01#>
@property(nonatomic,strong)MJRefreshAutoFooter *footer;

/**
 没有数据的 view
 */
@property(nonatomic,strong)ZDNoDataView *noDataView;

@end

@implementation ZDTableViewController

- (void)setupUI
{
    [super setupUI];
    self.view.backgroundColor = [UIColor whiteColor];
    
    //1.表格
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.height = LEScreenHeight - 64;
    [self.view addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.estimatedRowHeight = 120;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //2.没有数据的 view
    ZDNoDataView *noDataView = [[ZDNoDataView alloc]initWithFrame: CGRectMake(0, 200, self.view.width, 146)];
    noDataView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [self.tableView addSubview:noDataView];
    noDataView.hidden = YES;
    self.noDataView = noDataView;

}
- (void)loadData
{
    
}
- (void)initHeader
{
    ZDLog(@"%s---%d---初始化刷新头部",__func__,__LINE__);
    __weak typeof (self) weakSelf = self;
    self.header  = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        weakSelf.page = 1;
        [weakSelf requestRefreshData];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int16_t)(0.2*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.header endRefreshing];
        });
    }];
    [self.header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [self.header setTitle:@"松开刷新" forState:MJRefreshStatePulling];
    [self.header setTitle:@"正在刷新" forState:MJRefreshStateRefreshing];
    self.tableView.mj_header = self.header;
}
- (void)initFooter
{
    ZDLog(@"%s---%d---初始化刷新的脚视图",__func__,__LINE__);
    __weak typeof(self) weakSelf = self;
    self.footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        [weakSelf.header endRefreshing];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int16_t)(0.1*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.footer endRefreshing];
        });
        weakSelf.page++;
        if (weakSelf.page > [self.totalPage integerValue]) {
            [SVProgressHUD showInfoWithStatus:@"没有更多了"];
            weakSelf.page--;
            return ;
        }
        [self requestRefreshData];
        
    }];
    self.tableView.mj_footer = self.footer;

}

- (void)requestRefreshData;
{
    
}

- (void)resetTablewFrame:(CGRect)frame
{
    self.tableView.frame = frame;
    [self.tableView layoutIfNeeded];
}
- (void)addNoDataViewWithTipText:(NSString *)tipText
{
    self.noDataView.hidden = NO;
    [self.noDataView setNoDataText:tipText];
    
}
- (void)hiddenNoDataView
{
    self.noDataView.hidden = YES;
}
#pragma mark- 表格代理(虚函数)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"" forIndexPath:indexPath];
    
    return cell;
}
#pragma mark- getter
- (NSMutableArray *)dataSource
{
    if (_dataSource == nil) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

@end
